import { defineStore } from 'pinia'

// 创建一个全局的状态、容器
// 容器接收2个参数，第一个参数是容器id，这里是storeDemo；第二个参数是容器内容
// defineStore返回的是一个函数，这个函数按照useXXX去命名，这里是userStoreDemo
export const useStoreDemo = defineStore('storeDemo',{
    state: ()=>{
        return {
            msg: "Hello, Pinia"
        }
    }
})


export const useUserRoleStore = defineStore("userRole", {
  state: () => ({
    userRoleInfo: {}
  }),
  actions: {
    setUserRoleInfo(data) {
      this.userRoleInfo = data
      localStorage.setItem("userRoleInfo", JSON.stringify(data))
    },
    loadUserRoleInfo() {
      const stored = localStorage.getItem("userRoleInfo")
      if (stored) {
        this.userRoleInfo = JSON.parse(stored)
      }
    },
    clearUserRoleInfo() {
      this.userRoleInfo = {}
      localStorage.removeItem("userRoleInfo")
    }
  }
})


